// Package trip_rider 模型
package trip_rider

import (
	// "gitee.com/sweetsunnyflower/carpooling-server-go/pkg/logger"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/database"
)

// 行程乘客订单表
type TripRider struct {
	models.BaseModel

	UserId       uint64            `gorm:"column:user_id;comment:用户id;index;" db:"user_id" json:"user_id" form:"user_id"`
	TripId       uint64            `gorm:"column:trip_id;comment:行程id;" db:"trip_id" json:"trip_id" form:"trip_id"`           //乘车人ID
	RiderId      uint64            `gorm:"column:rider_id" db:"rider_id" json:"rider_id" form:"rider_id"`                     //乘车人ID
	BookingSeats int8              `gorm:"column:booking_seats" db:"booking_seats" json:"booking_seats" form:"booking_seats"` //预定座位数
	TotalPrice   float64           `gorm:"column:total_price" db:"total_price" json:"total_price" form:"total_price"`         //总价
	Commission   float64           `gorm:"column:commission" db:"commission" json:"commission" form:"commission"`             //佣金
	Deadline     models.FormatTime `gorm:"column:deadline" db:"deadline" json:"deadline" form:"deadline"`                     //拼车截止时间
	MatchStatus  int8              `gorm:"column:match_status" db:"match_status" json:"match_status" form:"match_status"`     //匹配状态，1：未匹配，2：已匹配
	OrderStatus  int8              `gorm:"column:order_status" db:"order_status" json:"order_status" form:"order_status"`     //订单状态，1：待确认，2：已同意，3：已拒绝, 4:乘客取消，5：自动取消
	TripStatus   int8              `gorm:"column:trip_status" db:"trip_status" json:"trip_status" form:"trip_status"`         //冗余行程表状态，1：进行中，2：等待发车，3：司机取消，4：行程结束
	Replay       string            `gorm:"type:varchar(255)" db:"replay" json:"replay" form:"replay"`                         //司机回复的内容
	Snapshot     string            `gorm:"column:snapshot" db:"snapshot" json:"snapshot" form:"snapshot"`                     //快照
	models.CommonTimestampsField
}

func (tripRider *TripRider) Create() {
	database.DB.Create(&tripRider)
}

func (tripRider *TripRider) Save() (rowsAffected int64) {
	result := database.DB.Save(&tripRider)
	return result.RowsAffected
}

func (tripRider *TripRider) Delete() (rowsAffected int64) {
	result := database.DB.Delete(&tripRider)
	return result.RowsAffected
}
